﻿using System.Collections.Generic;
using Dm.Domain.Repository.EntityRepositories;
using Dm.Domain.Entities;
using System.Linq;
using Dm.Domain.Repository.RepositoryBase;
using Dm.Domain.Repository.Factories;
using Dm.Domain.CrossCutting;

namespace Dm.Domain.Business
{
    public class StudentBusiness : BusinessBase, IBusinessBase<Student>
    {
        private IStudentRepository _studentRepository;
        
        public StudentBusiness()
        {
            this._studentRepository = ContextFactory.GetStudentRepository();
        }
       

        public List<Student> RetrieveAll(bool includeInactive = false)
        {
            return this._studentRepository.RetrieveAll(includeInactive);
            
        }

        public Student Create(Student entity)
        {
            return this._studentRepository.Create(entity);
        }

        public void Update(Student entity)
        {
            this._studentRepository.Update(entity);
        }

        public void Delete(Student entity)
        {
            this._studentRepository.Delete(entity);
        }

        public void Delete(int id)
        {
            this._studentRepository.Delete(id);
        }

        public IQueryable<Student> Retrieve(string firstName, string middleName, string lastName)
        {
            return this._studentRepository.SearchByName(firstName, middleName, lastName) as IQueryable<Student>;
        }


        public List<Student> Search(string firstName, string middleName, string lastName, string studentNumber, string email, string contactNumber, string address, bool includeInactive = false)
        {
            var result = this._studentRepository.SearchAllParameter(firstName, middleName, lastName, studentNumber, email, contactNumber, address);
            return result;
        }



        public Student Retrieve(int id)
        {
            return this._studentRepository.Retrieve(id);
        }

        public Student RetrieveWithDetails(int id, bool includeAddress = false, bool includeStatus = false)
        {
            return this._studentRepository.RetrieveWithDetails(id, includeAddress, includeStatus);
        }

        public List<Student> PagedSearch(int page, int rows, string firstName, string middleName, string lastName, string sidx, string sord, out int totalRows)
        {
            return this._studentRepository.PagedSearch(page, rows, firstName, middleName, lastName, sidx, sord,out totalRows);
        }
    }
}
